package cn.xmkeshe.back.impl;

import cn.xmkeshe.back.ILoggerServiceBack;
import cn.xmkeshe.dao.ILoggerDao;
import cn.xmkeshe.model.Logger;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
public class ILoggerServiceBackImpl implements ILoggerServiceBack {

  @Resource
  private ILoggerDao iLoggerDao;

  @Override
  @Transactional(readOnly = true)
  public Map<String, Object> system(int currentPage, int lineSize) {
    Map<String, Object> map = new HashMap<String,Object>();
    map.put("data", iLoggerDao.system((currentPage-1)*lineSize, lineSize));
    map.put("count", iLoggerDao.getAllCount());
    return map;
  }

  @Override
  @Transactional(readOnly = true)
  public Map<String, Object> driver(int currentPage, int lineSize) {
    Map<String, Object> map = new HashMap<String,Object>();
    map.put("data", iLoggerDao.driver((currentPage-1)*lineSize, lineSize));
    map.put("count", iLoggerDao.getAllCount());
    return map;
  }

  @Override
  @Transactional(readOnly = true)
  public Map<String, Object> customer(int currentPage, int lineSize) {
    Map<String, Object> map = new HashMap<String,Object>();
    map.put("data", iLoggerDao.customer((currentPage-1)*lineSize, lineSize));
    map.put("count", iLoggerDao.getAllCount());
    return map;
  }

  @Override
  @Transactional(readOnly = true)
  public Map<String, Object> admin(int currentPage, int lineSize) {
    Map<String, Object> map = new HashMap<String,Object>();
    map.put("data", iLoggerDao.admin((currentPage-1)*lineSize, lineSize));
    map.put("count", iLoggerDao.getAllCount());
    return map;
  }

  @Override
  @Transactional(propagation = Propagation.REQUIRED)
  public boolean delete(int id) {
    return iLoggerDao.delete(id);
  }

  @Override
  @Transactional(propagation = Propagation.REQUIRED)
  public boolean insert(Logger log) {
    return iLoggerDao.insert(log);
  }

  @Override
  @Transactional(readOnly = true)
  public Map<String, Object> findByCreateDate(int currentPage, int lineSize, String createDate) {
    Map<String,Object> map = new HashMap<String, Object>();
    map.put("data",iLoggerDao.findByCreateDate((currentPage-1)*lineSize, lineSize,createDate));
    map.put("count",iLoggerDao.getAllCount());
    return map;
  }
}
